package com.atguigu.gmall.product.controller.api;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.MangerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/api/product")
public class ProductApiController {

    @Autowired
    MangerService mangerService;

    // /api/product/inner/getSkuInfo/{skuId} skuId获取skuInfo
    @GetMapping("/inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId){
        SkuInfo skuInfo = mangerService.getSkuInfo(skuId);
        return skuInfo;
    }

    // /api/product/inner/getCategoryView/{category3Id}
    @GetMapping("/inner/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryViewBycategory3Id(@PathVariable Long category3Id){
        return mangerService.getCategoryViewBycategory3Id(category3Id);
    }

    // /api/product/inner/getSkuPrice/{skuId}
    @GetMapping("/inner/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable Long skuId){
        return mangerService.getSkuPrice(skuId);
    }

    // /api/product/inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}
    @GetMapping("/inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(@PathVariable Long skuId,
                                                          @PathVariable Long spuId){
        return mangerService.getSpuSaleAttrListCheckBySku(skuId,spuId);
    }

    // /api/product/inner/getSkuValueIdsMap/{spuId} 商品切换功能
    @GetMapping("/inner/getSkuValueIdsMap/{spuId}")
    public Map getSkuValueIdsMap(@PathVariable Long spuId){
        return mangerService.getSkuValueIdsMap(spuId);
    }

    ///api/product/inner/findSpuPosterBySpuId/{spuId}
    @GetMapping("/inner/findSpuPosterBySpuId/{spuId}")
    public List<SpuPoster> findSpuPosterBySpuId(@PathVariable Long spuId){
        return this.mangerService.findSpuPosterBySpuId(spuId);
    }

    ///api/product/inner/getAttrList/{skuId} 获取平台属性
    @GetMapping("/inner/getAttrList/{skuId}")
    List<BaseAttrInfo> getAttrList(@PathVariable("skuId") Long skuId){
        return mangerService.getAttrList(skuId);
    }
    // /api/product/getBaseCategoryList 获取全部分类信息
    @GetMapping("getBaseCategoryList")
    public Result getBaseCategoryList(){
        List<JSONObject> list =  mangerService.getBaseCategoryList();
        return Result.ok(list);
    }

    @GetMapping("inner/getTrademark/{tmId}")
    public BaseTrademark getTrademark(@PathVariable Long tmId){
        return mangerService.getTrademark(tmId);
    }
}
